package com.example.blog.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

//添加拦截器
@Configuration
public class WebConfig1 implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    //排除以下不需要拦截的
    private static  final List<String>excludepath= Arrays.asList(
            "/admin/captcha",
            "/user/login",
            "/**/*.html",
            "/pic/**",
            "/css/**",
            "/js/**",
            "/editor.md/**"
    );
    //添加需要拦截的
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns(excludepath);
    }
}
